package com.sc.pattern.future;

/**
 * Created  on 2018/1/7.
 *
 * @author sc
 */
public class AsyncFuture<T> implements Future<T>{

    private volatile  boolean done =false;

    private T result;

    public void done(T result){
        synchronized (this){
            this.result = result;
            this.done=true;
            this.notifyAll();
        }
    }

    @Override
    public T get() {
        synchronized (this){
            while (!done){
                try {
                    this.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
        return result;
    }
}
